/**
 * Copyright (c) 2011 ~ 2014 Deepin, Inc.
 *               2013 ~ 2014 jouyouyun
 *
 * Author:      jouyouyun <jouyouwen717@gmail.com>
 * Maintainer:  jouyouyun <jouyouwen717@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 **/

package main

// #cgo pkg-config: glib-2.0 gdk-3.0 x11 xi
// #cgo CFLAGS: -Wall -g
// #include <stdio.h>
// #include <stdlib.h>
// #include "common.h"
import "C"

import (
	"fmt"
	"unsafe"
)

type deviceInfo struct {
	name      string
	atom_name string
	id        int
	atom      int
}

func main() {
	n_devices := C.int(0)
	list := C.get_device_info_list(&n_devices)
	fmt.Printf("device info num: %v\n", n_devices)
	if n_devices < 1 {
		return
	}

	tmp := uintptr(unsafe.Pointer(list))
	for i := C.int(0); i < n_devices; i++ {
		t := unsafe.Sizeof(*list)
		fmt.Println(t)
		l := (*C.DeviceInfo)(unsafe.Pointer(tmp + uintptr(i)*t))
		fmt.Println(l)
		fmt.Printf("Name: %v\n", C.GoString(l.name))
		fmt.Printf("Atom Name: %v\n", C.GoString(l.Atom_name))
		fmt.Printf("Xid: %v\n", l.Xid)
		fmt.Printf("Atom: %v\n", l.Atom)
	}

	C.free(unsafe.Pointer(list))
}
